package com.kzj.controller;

import com.kzj.annotation.OnCreate;
import com.kzj.annotation.OnEdit;
import com.kzj.common.constant.GlobalConstant;
import com.kzj.common.enumerate.RoleEnum;
import com.kzj.common.result.Result;
import com.kzj.common.util.InheritableThreadLocalUtil;
import com.kzj.pojo.Score;
import com.kzj.pojo.dto.ScoreDto;
import com.kzj.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/score")
public class ScoreController {
    @Autowired
    ScoreService scoreService;
    @GetMapping("/getScoreVosByCourseIds/{courseIdsStr}")
    public Result getScoreVosByCourseIds(@PathVariable("courseIdsStr") String courseIdsStr)
    {
        List<Long> courseIds = Arrays.stream(courseIdsStr.split(",")).map(Long::valueOf).collect(Collectors.toList());
        return  scoreService.getScoreVosByCourseIds(courseIds);
    }
    @GetMapping("/getOptionalTermsByCourseId/{courseId}")
    public  Result getOptionalTermsByCourseId(@PathVariable("courseId") Long courseId)
    {
        return scoreService.getOptionalTermsByCourseId(courseId);
    }
    @PutMapping
    public Result update(@RequestBody @Validated(OnEdit.class) Score score)
    {
        return scoreService.updateScore(score);
    }
    @DeleteMapping("/{scoreId}")
    public Result deleteById(@PathVariable("scoreId") Long scoreId)
    {
        return scoreService.deleteById(scoreId);
    }
    @PostMapping
    public Result addByDto(@RequestBody ScoreDto dto)
    {
        System.out.println(dto);
        return scoreService.addScoreByDto(dto);
    }

}
